package com.violet.controller.app;

import com.violet.domain.dto.app.AAddressDto;
import com.violet.domain.result.Result;
import com.violet.domain.vo.app.AAddressVo;
import com.violet.service.app.AAddressService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/address")
@RequiredArgsConstructor
public class AAddressController {

    private final AAddressService service;

    // 获取登录用户的地址列表
    @GetMapping
    public Result<List<AAddressVo>> getAll() {
        return Result.success(service.getAll(), "获取登录用户所有地址");
    }

    @PostMapping
    public Result<AAddressVo> create(@RequestBody AAddressDto dto) {
        return Result.success(service.create(dto), "创建地址");
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable String id) {
        return Result.success(service.deleteById(id), "删除地址");
    }

    @PutMapping("/{id}")
    public Result<AAddressVo> updateById(@PathVariable String id, @RequestBody AAddressDto dto) {
        return Result.success(service.updateById(id, dto), "更新地址");
    }

    // 为登录用户设置默认地址
    @PutMapping("/set_default")
    public Result<Boolean> setDefault(@RequestParam String id) {
        return Result.success(service.setDefault(id), "设置默认值");
    }

}
